
#include "plugin/DynLibManager.h"
#include "plugin/DynLib.h"
namespace KCore
{

	DynLibManager::DynLibManager()
	{
	}

	DynLib* DynLibManager::load( const char* name)
	{
		DynMap::iterator i = _dynLibs.find(name);
		if (i != _dynLibs.end())
		{
			return i->second;
		}
		else
		{
			DynLib* lib = new DynLib(name,this);
			lib->load();        
			_dynLibs[name] = lib;
			return lib;
		}
	}
	//-----------------------------------------------------------------------
	void DynLibManager::unload(const char* name)
	{
		DynMap::iterator i = _dynLibs.find(name);
		if (i != _dynLibs.end())
		{

			i->second->unload();
			delete i->second;

			_dynLibs.erase(i);
		}
	}
	//-----------------------------------------------------------------------
	DynLibManager::~DynLibManager()
	{
		for( DynMap::iterator it = _dynLibs.begin(); it != _dynLibs.end(); ++it )
		{
			it->second->unload();
			delete it->second;
		}
		_dynLibs.clear();
	}

};
